/*
Copyright 2014, KISSY v1.47
MIT Licensed
build time: May 22 12:30
*/
KISSY.add("scroll-view/base/render",["component/container","component/extension/content-render"],function(i,g){var n=g("component/container"),o=g("component/extension/content-render"),p=i.Features,j=Math.floor,l,m=i.Features.isTransform3dSupported(),k={syncUI:function(){var e=this.control,a=e.el,b=e.contentEl,c=Math.max(b.offsetHeight,b.scrollHeight),b=Math.max(b.offsetWidth,b.scrollWidth);e.set("dimension",{scrollHeight:c,scrollWidth:b,clientWidth:a.clientWidth,clientHeight:a.clientHeight})},_onSetScrollLeft:function(e){this.control.contentEl.style.left=
-e+"px"},_onSetScrollTop:function(e){this.control.contentEl.style.top=-e+"px"}};!1!==i.Features.getVendorCssPropPrefix("transform")&&(l=p.getVendorCssPropName("transform"),k._onSetScrollLeft=function(e){var a=this.control;a.contentEl.style[l]="translateX("+j(-e)+"px) translateY("+j(-a.get("scrollTop"))+"px)"+(m?" translateZ(0)":"")},k._onSetScrollTop=function(e){var a=this.control;a.contentEl.style[l]="translateX("+j(-a.get("scrollLeft"))+"px) translateY("+j(-e)+"px)"+(m?" translateZ(0)":"")});return n.getDefaultRender().extend([o],
k,{name:"ScrollViewRender"})});
KISSY.add("scroll-view/base",["node","anim","component/container","./base/render"],function(i,g){function n(){var a=this.el,b=a.scrollTop,c=a.scrollLeft;b&&this.set("scrollTop",b+this.get("scrollTop"));c&&this.set("scrollLeft",c+this.get("scrollLeft"));a.scrollTop=a.scrollLeft=0}function o(a,b){a.scrollView.set(b.prop,b.val)}var p=g("node"),j=g("anim"),l=g("component/container"),m=g("./base/render"),k=i.all,e=p.KeyCode;return l.extend({initializer:function(){this.scrollAnims=[]},bindUI:function(){this.$el.on("mousewheel",
this.handleMouseWheel,this).on("scroll",n,this)},_onSetDimension:function(a){var b=this.$contentEl,c=a.scrollHeight,d=a.scrollWidth,f=a.clientHeight,e,h=a.clientWidth;this.scrollHeight=c;this.scrollWidth=d;this.clientHeight=f;this.clientWidth=h;e=this.allowScroll={};c>f&&(e.top=1);d>h&&(e.left=1);this.minScroll={left:0,top:0};var r,g;this.maxScroll={left:r=d-h,top:g=c-f};delete this.scrollStep;f=this.get("snap");c=this.get("scrollLeft");d=this.get("scrollTop");if(f){var i=b.offset(),b=this.pages=
"string"===typeof f?b.all(f):b.children(),f=this.get("pageIndex"),j=this.pagesOffset=[];b.each(function(a,b){var c=a.offset(),d=c.left-i.left,c=c.top-i.top;d<=r&&c<=g&&(j[b]={left:d,top:c,index:b})});if(f){this.scrollToPage(f);return}}this.scrollToWithBounds({left:c,top:d});this.fire("reflow",a)},handleKeyDownInternal:function(a){var b=k(a.target),c=b.nodeName();if(!("input"===c||"textarea"===c||"select"===c||b.hasAttr("contenteditable"))){var a=a.keyCode,b=this.getScrollStep(),d,c=this.allowScroll.left;
if(this.allowScroll.top){var f=b.top,q=this.clientHeight,h=this.get("scrollTop");a===e.DOWN?(this.scrollToWithBounds({top:h+f}),d=!0):a===e.UP?(this.scrollToWithBounds({top:h-f}),d=!0):a===e.PAGE_DOWN?(this.scrollToWithBounds({top:h+q}),d=!0):a===e.PAGE_UP&&(this.scrollToWithBounds({top:h-q}),d=!0)}c&&(b=b.left,c=this.get("scrollLeft"),a===e.RIGHT?(this.scrollToWithBounds({left:c+b}),d=!0):a===e.LEFT&&(this.scrollToWithBounds({left:c-b}),d=!0));return d}},getScrollStep:function(){if(this.scrollStep)return this.scrollStep;
var a=k(this.get("el")[0].ownerDocument),b=this.clientHeight,c=this.clientWidth;return this.scrollStep={top:Math.max(0.7*b*b/a.height(),20),left:Math.max(0.7*c*c/a.width(),20)}},handleMouseWheel:function(a){if(!this.get("disabled")){var b,c,d=this.getScrollStep(),f,e=this.maxScroll,h=this.minScroll;if((f=a.deltaY)&&this.allowScroll.top){var g=this.get("scrollTop");b=e.top;c=h.top;g<=c&&0<f||g>=b&&0>f||(this.scrollToWithBounds({top:g-a.deltaY*d.top}),a.preventDefault())}if((f=a.deltaX)&&this.allowScroll.left)g=
this.get("scrollLeft"),b=e.left,c=h.left,g<=c&&0<f||g>=b&&0>f||(this.scrollToWithBounds({left:g-a.deltaX*d.left}),a.preventDefault())}},stopAnimation:function(){this.scrollAnims.length&&(i.each(this.scrollAnims,function(a){a.stop()}),this.scrollAnims=[]);this.scrollToWithBounds({left:this.get("scrollLeft"),top:this.get("scrollTop")})},_uiSetPageIndex:function(a){this.scrollToPage(a)},getPageIndexFromXY:function(a,b,c){var d=this.pagesOffset.concat([]),f=b?"left":"top";d.sort(function(a,b){return a[f]-
b[f]});if(0<c)for(b=0;b<d.length;b++){if(c=d[b],c[f]>=a)return c.index}else for(b=d.length-1;0<=b;b--)if(c=d[b],c[f]<=a)return c.index},scrollToPage:function(a,b){var c;if((c=this.pagesOffset)&&c[a])this.set("pageIndex",a),this.scrollTo(c[a],b)},scrollToWithBounds:function(a,b){var c=this.maxScroll,d=this.minScroll;a.left&&(a.left=Math.min(Math.max(a.left,d.left),c.left));a.top&&(a.top=Math.min(Math.max(a.top,d.top),c.top));this.scrollTo(a,b)},scrollTo:function(a,b){var c=a.left,d=a.top;if(b){var f=
{},e={};void 0!==c&&(e.scrollLeft=c,f.scrollLeft=this.get("scrollLeft"));void 0!==d&&(e.scrollTop=d,f.scrollTop=this.get("scrollTop"));b.frame=o;b.node=f;b.to=e;this.scrollAnims.push(c=new j(b));c.scrollView=this;c.run()}else void 0!==c&&this.set("scrollLeft",c),void 0!==d&&this.set("scrollTop",d)}},{ATTRS:{contentEl:{},scrollLeft:{view:1,value:0},scrollTop:{view:1,value:0},dimension:{},focusable:{value:!0},allowTextSelection:{value:!0},handleMouseEvents:{value:!1},snap:{value:!1},pageIndex:{value:0},
xrender:{value:m}},xclass:"scroll-view"})});
